Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Chattering detected around time 80.00......

Chattering detected around time 80.00......

Hi,
I tried to simulate the model below, which consists of two variables h1 and h2 which represents the liquid level of two tanks serial connected. where we only control the output flow (o1 and o2). The goal is to maintain the liquid level between the Min and Max levels. of1 and of2 are the flow rate of the valves when opened. s is the flow rate from the source to the first tank.
I choosed the simulation step size to be 1s and duration of 1000s (which means 1000 steps).
The simulation freezes at 8% whith the folowing message :

The initialization finished successfully without homotopy method.
Chattering detected around time 80.0000000081..80.000001612 (100 state events in a row with a total time delta less than the step size 1). This can be a performance bottleneck. Use -lv LOG_EVENTS for more information. The zero-crossing was: h1 >= max1.

Pls tell me how to make it works. I desperately need it.
Thank you.

model TankSystem
        parameter Real s=1.0;
    Real h1(start=0.0);
    Real o1;
    parameter Real of1=2.0;
    parameter Real min1=20.0;
    parameter Real max1=80.0;
    Real h2(start=0.0);
    Real o2;
    parameter Real of2=3.0;
    parameter Real min2=20.0;
    parameter Real max2=80.0;
    initial equation
        h1=0.0;
        h2=0.0;
    equation
        if h1 >= max1 then
          o1 = of1;
         elseif h1 <= min1 then
          o1 = 0.0;
        else o1=o1;
        end if;
        der(h1) = s - o1;
        if h2 >= max2 then
          o2 = of2;
        elseif h2 <= min2 then
          o2 = 0.0;
        else o2=o2;
        end if;
        der(h2) = o1 - o2;
end TankSystem;

Edited by: YacinOS - May-16-18 11:29:01

Re: Chattering detected around time 80.00......

From your model description, the valves for the outflow of both tanks are controlled with hysteresis. The outlet valve should be opened as soon as the maximum level in a tank is reached and only close again when the level has fallen to the minimum.

You have used an if-clause for the controller, but that doesn't work. Starting at time t=0 with an empty tank 1 with a continuous inflow and closed outlet valve, the water level raises until the if expression h1>=max1 becomes true for the first time and the outlet valve will be opened. As the if-clause will be evaluated whenever any of the conditional expressions changes, it will switch very fast between the 'if h1>=max1'-branch and the else-branch and cause the chattering. The equation 'o1=o1' in the else-branch might also cause problems.

To implement the hysteresis, the last state of the valve must be taken into account. For this, a when statement is needed, that only activates equations when the defined condition becomes true. For your model a solution could be:

Code:

model TankSystem 

    parameter Real s=1.0;
    Real h1(start=0.0);
    Real o1;
    parameter Real of1=2.0;
    parameter Real min1=20.0;
    parameter Real max1=80.0;
    Real h2(start=0.0);
    Real o2;
    parameter Real of2=3.0;
    parameter Real min2=20.0;
    parameter Real max2=80.0;
               
equation
    der(h1) = s - o1;
    der(h2) = o1 - o2;
   
    // control valve 1 for outflow of tank 1 with hysteresis
    when h1>max1 then
      o1 = of1;
    elsewhen h1<min1 then
      o1 = 0;     
    end when;
       
    // control valve 2 for outflow of tank 2 with hysteresis
    when h2>max2 then
      o2 = of2;
    elsewhen h2<min2 then
      o2 = 0;     
    end when;
     
end TankSystem;

Re: Chattering detected around time 80.00......

Well the result looks pretty much what I needed, thanks.
If I understand your words, the changes made by the "when" statement are preserved, whereas those made by the "if" are not meant to last.

Edited by: YacinOS - May-17-18 12:58:46

Re: Chattering detected around time 80.00......

hi, am facing the same error in openModelica and am usinf when and not if,can some one help me

Re: Chattering detected around time 80.00......

Follow the guidelines given above. The error message tells you that your system is switching very fast between two states. This forces the integrator (dassl, etc) to restart frequently, killing performance.

Using some hysteresis is probably best. And sometimes noEvent() can help you in if-statements.

Re: Chattering detected around time 80.00......

hi am having the same problem and am using when condition ,i tried the "noEvant" and i still have the same error msg and even with a hysterisis

Edited by: merzaka - Nov-21-19 16:12:17
There are 0 guests and 0 other users also viewing this topic
You are here: